<?php
namespace My\Model;

use Utuo\UtuoModel;

class DistributionShopJobTitleModel extends UtuoModel {

	/**
	 * 获得头衔初始列表
	 * @return 
     * array(
     *   '类型id' => array(
     *      'hasLevel' => 0,
     *      'name' => '',
     *   );
     * )
	 */
	public static function getJobTitleList( $cid ) {
		$jobTitleList = M("DistributionShopJobTitle a")->join("__DISTRIBUTION_SHOP_JOB_TITLE_ALIAS__ b on a.id = b.type and b.cid = {$cid}", "LEFT")
										->field("a.id,a.hasLevel,(case length(b.aliasName)>0 when 1 then b.aliasName else a.name end) as name,b.levelAlias")
										->select();
		$data = array();
		foreach ( $jobTitleList as $v ) {
		    $data[$v['id']] = array(
		        'hasLevel' => $v['hasLevel'],
		        'name' => $v['name'],
		        'levelAlias' => $v['levelAlias'] ? unserialize( $v['levelAlias'] ) : null,
		    );
		}
		return $data;
	}
	
}